﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sys.WebRes.Data;

namespace Sys.WebRes.Publish.Controllers
{
    public class TempController : Controller
    {
        //
        // GET: /Temp/

        public ActionResult Index()
        {
            using (var db = new ResourceSysEntities())
            {
                //db.SectionTBL.DeleteAllData();
                //db.LanguageTBL.DeleteAllData();
                //db.ResStatusTypeTBL.DeleteAllData();
                //db.ResTypeTBL.DeleteAllData();

                db.AddToLanguageTBL(new Language() { ID = 1, Name = "中文", Abbr = "CN", OrderNo = 1 });
                db.AddToLanguageTBL(new Language() { ID = 2, Name = "英文", Abbr = "EN", OrderNo = 2 });
                db.SaveChanges();

                db.AddToResTypeTBL(new ResType() { ID = 1, Name = "文章", Abbr = "Article", OrderNo = 1 });
                db.AddToResTypeTBL(new ResType() { ID = 2, Name = "媒体", Abbr = "Media", OrderNo = 2 });
                db.AddToResTypeTBL(new ResType() { ID = 3, Name = "图片", Abbr = "Picture", OrderNo = 3 });
                db.AddToResTypeTBL(new ResType() { ID = 4, Name = "文件", Abbr = "File", OrderNo = 4 });
                db.AddToResTypeTBL(new ResType() { ID = 5, Name = "文件夹", Abbr = "Folder", OrderNo = 5 });
                db.SaveChanges();

                db.AddToResStatusTypeTBL(new ResStatusType() { ID = 1, Name = "未审核", Abbr = "Unreviewed", OrderNo = 1 });
                db.AddToResStatusTypeTBL(new ResStatusType() { ID = 2, Name = "审核", Abbr = "Reviewed", OrderNo = 2 });
                db.AddToResStatusTypeTBL(new ResStatusType() { ID = 3, Name = "公开", Abbr = "Publish", OrderNo = 3 });
                db.AddToResStatusTypeTBL(new ResStatusType() { ID = 4, Name = "关闭", Abbr = "Close", OrderNo = 4 });
                db.AddToResStatusTypeTBL(new ResStatusType() { ID = 5, Name = "回收站", Abbr = "Recycle", OrderNo = 5 });
                db.SaveChanges();

                db.AddToSectionTBL(new Section() { ID = 1, Name = "新闻", Abbr = "News", Summary = "新闻", OrderNo = 1,
                                                    ResType=db.ResTypeTBL.FirstOrDefault(p=>p.ID == 1) ,
                                                    StatusType = db.ResStatusTypeTBL.FirstOrDefault(p => p.ID == 1),
                                                    Language = db.LanguageTBL.FirstOrDefault(p => p.ID == 1)});

                db.SaveChanges();
            }

            return View();
        }

    }
}
